﻿@{
    Bundle("jquery_validate");
    Bundle("browserStorage");
    Bundle("browserInput");
}

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('@ID("#form")').validate({
            rules: {
                city: {
                    required: true
                },
                address1: {
                    required: true
                },
                contactName: {
                    required: true
                },
                postalCode: {
                    required: true
                },
                email: {
                    required: true,
                    email: true
                }
            }
        });
        jQuery('@ID("#ddl_country")').bind('change', function () {
            jQuery.ajax({
                type: 'post',
                url: '@Url.Action(Loc.Act("Regions").Ctrl("Configuration").NoArea())',
                dataType: 'json',
                data: {
                    countryID: jQuery('@ID("#ddl_country")').val()
                },
                success: function (rsp) {
                    var ddl = jQuery('@ID("#ddl_region")');
                    ddl.empty();
                    jQuery.each(rsp, function (k, v) {
                        ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                    });
                }
            });
        });
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("Countries").Ctrl("Configuration").NoArea())',
            dataType: 'json',
            success: function (rsp) {
                var ddl = jQuery('@ID("#ddl_country")');
                ddl.empty();
                jQuery.each(rsp, function (k, v) {
                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                });
                ddl.change();
            }
        });
        jQuery('@ID("#form")').browserInput({
            key: '@Par.In("UserStorage").Of("Input").Name(ViewID)',
            includes: 'input',
            excludes: 'select',
            reset: '@((TempData.RestoreStatus() >= 0).ToString().ToLowerInvariant())'
        });
    });
</script>
<form class="page-form" id="@ID("form")" action="@Url.Action(Loc.Act("Create").Localized())" method="post">
    <table>
        <tr>
            <td>
                <label>@T(Res.Name("Country"))</label>
            </td>
            <td>
                <select id="@ID("ddl_country")" name="countryID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Region"))</label>
            </td>
            <td>
                <select id="@ID("ddl_region")" name="regionID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("City"))</label>
            </td>
            <td>
                <input type="text" name="city" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Address1"))</label>
            </td>
            <td>
                <input type="text" name="address1" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Address2"))</label>
            </td>
            <td>
                <input type="text" name="address2" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("ContactName"))</label>
            </td>
            <td>
                <input type="text" name="contactName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("PostalCode"))</label>
            </td>
            <td>
                <input type="text" name="postalCode" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("PhoneNumber"))</label>
            </td>
            <td>
                <input type="text" name="phoneNumber" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("FaxNumber"))</label>
            </td>
            <td>
                <input type="text" name="faxNumber" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("Common").Of("Vocab").Name("Email"))</label>
            </td>
            <td>
                <input type="text" name="email" />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>